#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QMessageBox>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
     ,worker(new WorkerThread())
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
    worker->wait(); //如果不要这一句，直接delete
                   // 如果线程还在运行程序会崩溃。
    delete  worker;
}


void Widget::on_pushButton_clicked()
{
    worker->start();
}

void Widget::on_pushButton_2_clicked()
{
    QMessageBox::warning(this, tr("title"),
                         tr("Hi ."));
}


void Widget::on_pushButton_3_clicked()
{
    WorkerThread worker2; //局部变量
    worker2.start();
}

void Widget::on_pushButton_4_clicked()
{
    worker->setButton(ui->pushButton_4);
    worker->start();
}
